<!DOCTYPE html>
<html lang="en">

<head>
  <meta charset="UTF-8">
  <meta http-equiv="X-UA-Compatible" content="IE=edge">
  <meta name="viewport" content="width=device-width, initial-scale=1.0">
  <title>5、有效的正方形</title>
</head>

<body>
  <script>
    var distance = function (p1, p2) {
      let a = p1[0] - p2[0];
      let b = p1[1] - p2[1];

      return Math.sqrt(a * a + b * b);
    }

    var array = function (p1, p2, p3, p4) {
      let arr = [];
      let d12 = distance(p1, p2);
      let d13 = distance(p1, p3);
      let d14 = distance(p1, p4);
      let d23 = distance(p2, p3);
      let d24 = distance(p2, p4);
      let d34 = distance(p3, p4);
      arr = [d12, d13, d14, d23, d24, d34];
      arr.sort((a, b) => a - b);

      return arr[0] == arr[3] && arr[4] == arr[5] && arr[3] < arr[4];
    }
    console.log(array([0, 0], [1, 1], [1, 0], [0, 1]))
  </script>
</body>

</html>